{% extends 'view_page.html' %}

{% block stylesheets %}
	{{ block.super }}
	<link rel="stylesheet" content="text/css" href="/static/css/test.view_test.css" />
	<link rel="stylesheet" content="text/css" href="/static/css/page.view_test.css" />
{% endblock %}
 
{% comment %}
Block for adding additional buttons to the left of the 'edit page'-button {% endcomment %}
{% block page_buttons %}
{% endblock %} 

{% block page_content %}
	{{ block.super }}
	
	{% if test_type = "ProgressCheck" %}
		{% include '_admin_progress.html' %}
	{% endif %}
	<legend>Questions</legend>
	<!-- Questions -->
	{% if user.is_staff and not request.session.viewing_as_student %}
		{% if questions %}
			<form id="reorder-question-form" action="{% url 'test.views.rearrange_questions_in_test' test_id=page.id %}">
			</form>
			
			<form id="remove-question-form" action="{% url 'test.views.remove_question' test_id=page.id %}"></form>

				<ol id="admin-question-list">
				{% for question in questions %}
					<li id="question_{{ question.id }}">
						<div class="admin-question">
							<div class="admin-question-handle">
							</div>
							{{ question|truncatechars:90 }}
							<div class="admin-question-buttons pull-right">
                                <a href="{% url 'question.views.edit' question_id=question.id test_id=page.id %}"><i class="icon-edit"></i></a>
								<i class="remove-question icon-remove"></i>
							</div>
						</div>
					</li>
				{% endfor %}
				</ol>
		{% else %}
			<p>No questions have been added to this test yet.</p>
		{% endif %}
		<!-- Action buttons -->
		<hr />
        <a href="{% url 'question.views.new' test_id=page.id %}" class="btn btn-primary"><i class="icon-plus icon-white"></i> Add a new question</button>
		<a href="{% url 'test.views.filter_questions' page_id=page.id %}" class="btn" type="button"><i class="icon-plus"></i> Add existing question to test</a>
	{% else %}
		{% if questions %}
			<form id="question-form" class="form-inline" method="POST" action="#">
				{% csrf_token %}
				{% for question in questions %}
					{% load question_extras %}
					{% show_question question %}
				{% endfor %}

				<!-- Action buttons -->
				<hr />
				<div id="result" class="alert alert-info"></div>
				<button id="submit" class="btn btn-primary">Correct my answers</button>
				<button id="retake" class="btn btn-secondary">Take the test again</button>
			</form>
		{% else %}
			<p>No questions have been added to this test yet.</p>
		{% endif %}

	{% endif %}

{% endblock %}

{% block page_footer %}
	{{ block.super }}
{% endblock %}

{% block scripts %}
	{{ block.super }}
	<script type="text/javascript" src="/static/script/test.view_test.js"></script>
	{% if user.is_staff %}
		<script type="text/javascript" src="/static/script/setup_ajax.js"></script>
		<script type="text/javascript" src="/static/script/page.view_test.reorder.js"></script>
		<script type="text/javascript" src="/static/script/page.view_test.remove.js"></script>
	{% endif %}
{% endblock %}
